<template>
<div>
  <el-table
    :data="applications"
    style="width: 100%"
    border
    >

     <el-table-column
      prop="customer.user.name"
      label="客户"
      align='center'
      >
    </el-table-column>

     <el-table-column
      prop="product.name"
      label="产品"
      align='center'
      >
    </el-table-column>

     <el-table-column
      prop="money"
      label="金额"
      align='center'
      >
    </el-table-column>

    <el-table-column
      label="日期"
      align='center'
      prop="applyTime">
     
    </el-table-column>

     <el-table-column
      prop="acceptAccount"
      label="收款账号"
      align='center'
      >
    </el-table-column>

    <el-table-column label="操作" align='center'>
      <template slot-scope="scope">
        <!-- <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button> -->
          <el-button
          size="mini"
          type="danger"
          @click="handleExamine(scope.$index, scope.row)">审核</el-button>
      </template>
    </el-table-column>

  </el-table>

    <el-dialog title="申请信息" :visible.sync="dialogTableVisible" v-if="application!=''">
        <el-descriptions title="客户信息"   >
            <el-descriptions-item label="客户姓名" >{{application.customer.user.name}}</el-descriptions-item>
            <el-descriptions-item label="客户性别">{{application.customer.user.gender}}</el-descriptions-item>
            <el-descriptions-item label="客户年龄">{{application.customer.user.age}}</el-descriptions-item>
            <el-descriptions-item label="居住地">{{application.customer.user.address}}</el-descriptions-item>
            <el-descriptions-item label="客户等级">{{application.customer.level}}</el-descriptions-item> 
            <el-descriptions-item label="业务员">{{application.customer.emp.name}}</el-descriptions-item> 
            <el-descriptions-item label="备注">
            <el-tag size="small">{{application.customer.level=='A'?'优质客户':'普通客户'}}</el-tag>
            </el-descriptions-item>
        </el-descriptions>

        <el-descriptions title="产品信息">
            <el-descriptions-item label="产品名称">{{application.product.name}}</el-descriptions-item>
            <el-descriptions-item label="最大金额">{{application.product.maxMoney}}</el-descriptions-item>
            <el-descriptions-item label="年利率">{{application.product.rate*100+'%'}}</el-descriptions-item>
        </el-descriptions>

        <el-descriptions title="抵押资产" direction="vertical" :column="3" border>
            <el-descriptions-item v-for="(mor,index) in application.mortgageList" :key="mor.id" :label="index+1+':'+mor.name">
                <el-descriptions :column="1" >
                    <el-descriptions-item label="资产估值">{{mor.valuation}}</el-descriptions-item>
                    <el-descriptions-item label="评估公司">{{mor.company.name}}</el-descriptions-item>
                </el-descriptions>
            </el-descriptions-item>
        </el-descriptions>
    
        <el-descriptions title="申请信息" :column="1">
            <el-descriptions-item label="贷款金额">{{application.money}}</el-descriptions-item>
            <el-descriptions-item label="收款账号">{{application.acceptAccount}}</el-descriptions-item>
            <el-descriptions-item label="申请时间">{{application.applyTime}}</el-descriptions-item>
            <el-descriptions-item label="审核意见">
                <el-input v-model="result" placeholder="请输入审核意见" class="aaa" size="mini"></el-input>
                </el-descriptions-item>
        </el-descriptions>
        
        <el-descriptions title="操作记录" :column="2">
            <el-descriptions-item v-for="(pro,index) in  application.processList" :key="pro.id" :label="index+1">{{pro.handle.name}}</el-descriptions-item> 
            <el-descriptions-item v-for="(pro) in  application.processList" :key="pro.id" label="操作时间">{{pro.time}}</el-descriptions-item> 
        </el-descriptions>
        

        <div style="text-align:center">
            <el-button type="primary" @click="examine(2)" size="small">同意</el-button>
            <el-button type="danger" @click="examine(3)" size="small">拒绝</el-button>
        </div> 
    </el-dialog>
</div>

</template>

<script>
import global from '@/global.js';
  export default {
    created() {
        /**
         * 获取所有未审核申请表
        */
        this.$axios.post(global.server + '/api/app/condition',
        {
            "status":"1"
        }).then(response => {
                let result = response.data;
                if (result.code == 200) {
                    this.applications = result.data;
                    console.log("applications---->",this.applications);
                }
            });
    },
    data() {
      return {
        applications:[],
        tableData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }],
        dialogTableVisible: false,
        application:'',
        result:'',
      }
    },
    methods: {
    /**
     * 编辑
     */
      handleEdit(index, row) {
        console.log(index, row);
        this.dialogTableVisible = true;
      },
      /**
       * 审核
       */
      handleExamine(index, row) {
        console.log(index, row);
        this.dialogTableVisible = true;
        this.application = row;
      },

    /**
     * 审核结果
     */
        examine(resultID){
            /**
             * 更新申请表和操作记录
             */
            this.$axios.post(global.server + '/api/app/examine',
            {
                "appId":this.application.id,
                "status":resultID,
                'result':this.result
            }).then(response => {
                let result = response.data;
                if (result.code == 200) {
                    this.$alert(resultID==2?"审核通过!":"审核拒绝");
                    this.dialogTableVisible = false;
                    //更新未审核的列表
                    this.del(this.application);

                    this.application='';

                }
            });
        },
        /**
         * 删除已审核的申请信息
         */
        del:function(application){
            //表示先获取这个元素的下标，然后从这个下标开始计算，删除长度为1的元素
            this.applications.splice(this.applications.indexOf(application),1);
        }
    }
  }
</script>
<style scoped>

    .aaa{
      width: 300px;
    }
    
</style>